using System;
using System.Drawing;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace iDorm
{
	// class Object
	//
	// Base class for any item that can be placed in the room
	public class Object
	{
		private int x, y, z;
		private int length, width, height;
		

		public bool moving = false;

		CustomVertex.TransformedColored [] verts;

		// 3D representation of object
		Model model;


		public Object(int x, int y, int length, int width, int height)
		{
			this.x = x;
			this.y = y;
			this.length = length;
			this.width = width;
			this.height = height;
			this.z = 0;

			// set up verts for 2D viewing
			verts = new CustomVertex.TransformedColored[5];
			verts[0] = new CustomVertex.TransformedColored(
				new Vector4(x, y, z, 1.0f),
				0x0000000);
			verts[1] = new CustomVertex.TransformedColored(
				new Vector4(x + width, y, z, 1.0f),
				0x0000000);
			verts[2] = new CustomVertex.TransformedColored(
				new Vector4(x + width, y + length, z, 1.0f),
				0x0000000);
			verts[3] = new CustomVertex.TransformedColored(
				new Vector4(x, y + length, z, 1.0f),
				0x0000000);
			verts[4] = new CustomVertex.TransformedColored(
				new Vector4(x, y, z, 1.0f),
				0x0000000);
		}

		public void Move(int x, int y)
		{
			this.x = x;
			this.y = y;

			//mat = Matrix.Translation(x + width / 2, height / 2, y + length / 2);
		
			verts[0] = new CustomVertex.TransformedColored(
				new Vector4(x, y, z, 1.0f),
				0x0000000);
			verts[1] = new CustomVertex.TransformedColored(
				new Vector4(x + width, y, z, 1.0f),
				0x0000000);
			verts[2] = new CustomVertex.TransformedColored(
				new Vector4(x + width, y + length, z, 1.0f),
				0x0000000);
			verts[3] = new CustomVertex.TransformedColored(
				new Vector4(x, y + length, z, 1.0f),
				0x0000000);
			verts[4] = new CustomVertex.TransformedColored(
				new Vector4(x, y, z, 1.0f),
				0x0000000);
		
		
		}

		public void Render2D(Device dev)
		{
			// draw a box and text
			dev.VertexFormat = CustomVertex.TransformedColored.Format;
			dev.DrawUserPrimitives(PrimitiveType.LineStrip, 4, verts);
 
		}

		public void Render3D()
		{
		}

		public Point Intersects(Point p)
		{
			Point tmp = new Point(-1, -1);

			if ((p.X > this.x && p.X < this.x + width) && (p.Y > this.y && p.Y < this.y + length))
			{
				tmp.X = p.X - this.x;
				tmp.Y = p.Y - this.y;
			}
			return tmp;
		}
	}
}
